package com.zjpavt.client.artnet.effect;

import com.zjpavt.client.artnet.device.ColorConst;
import com.zjpavt.client.artnet.device.StripLight;

/**
 * @author zyc
 * 正弦波 速度为负数的时候向下 速度为正数的时候向上
 */

public class SinWaveEffect implements IEffect {

    private transient  StripLight stripLight;
    private byte[] runColor;
    private double variate;
    private int period;
    private double initialPhase;
    private double speed = 1;
    public SinWaveEffect(StripLight stripLight, byte[] runColor, int period, double initialPhase,double speed) {
        this.stripLight = stripLight;
        this.runColor = runColor;
        this.period = period;
        this.initialPhase = initialPhase;
        this.speed = speed;
    }

    /**
     *
     * @param timeout
     */
    public void setTimeout(long timeout) {
//        this.timeout = timeout + System.currentTimeMillis();
    }

    @Override
    public void show() {
        int channelNum = stripLight.getSingleLightChannelSize();
        int lightNum = stripLight.getLightNum();
        if (channelNum != runColor.length || stripLight == null) {
            return;
        }
        for (int index = 0; index < stripLight.getLightNum(); index++) {
            double fudu = (Math.sin((Math.PI * 2 * index + variate + initialPhase) /period) +1) /2;
            byte[] color = ColorConst.tiaoxiang(runColor, fudu);
            stripLight.setLightColor(index,color);
        }
        variate+= speed;
//        variate = variate % period;
        return;
    }

    @Override
    public void setOwner(StripLight stripLight) {
        this.stripLight = stripLight;
    }
}
